<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\finance\cost;

use app\enum\CommonEnum;
use app\service\finance\FinanceService;

final class CostService extends FinanceService
{
    private static array $handle = [];

    private static array $service = [
        CommonEnum::OE_MEDIA => '\app\service\finance\cost\OeCostAccountService',
        CommonEnum::KS_MEDIA => '\app\service\finance\cost\KsCostAccountService',
        CommonEnum::QQ_MEDIA => '\app\service\finance\cost\QqCostAccountService',
    ];

    private function __construct()
    {
    }

    /**
     * 获取实例.
     * @param int $mediaId 媒体id
     */
    public static function getInstance(int $mediaId = 0)
    {
        if (! isset(self::$handle[$mediaId])) {
            $classname = self::$service[$mediaId] ?? '';
            if (! $classname) {
                return self::setError('未知消耗媒体类型');
            }
            self::$handle[$mediaId] = new $classname();
        }
        return self::$handle[$mediaId];
    }

    private function __clone()
    {
    }
    private function __wakeup()
    {
    }
}
